package com.jade.linkong.task;

import com.github.pagehelper.PageHelper;
import com.jade.linkong.domain.LkMatterProject;
import com.jade.linkong.mapper.LkNoticeMapper;
import com.jade.linkong.service.ILkMatterProjectService;
import com.jade.linkong.service.ILkNoticeService;
import com.jade.linkong.service.ILkPenaltiesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class LightTask {

	@Autowired
	private ILkMatterProjectService lkMatterProjectService;

	@Autowired
	private ILkPenaltiesService lkPenaltiesService;
	@Autowired
    private LkNoticeMapper lkNoticeMapper;
	@Autowired
	private ILkNoticeService lkNoticeService;

//	@Scheduled(cron = "1 * * * * ?")
//	@Scheduled(cron = "* */5 * * * ?")
	public void setLight() {
		LkMatterProject lmp=new LkMatterProject();
		//找事项表，没有完成的，并且超时的。
		List<LkMatterProject> distinctLight = lkMatterProjectService.getDistinctLight(lmp);

		for (LkMatterProject lkMatterProject : distinctLight) {
			try {
				lkPenaltiesService.jobAddOrUpdate(lkMatterProject);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}

	/**
	 * 查询事项是否超时并添加告示单
	 */
//	@Scheduled(cron = "*/5 * * * * ?")
	@Scheduled(cron = "0 0 1 * * ?")
	public void generateNotice(){
		PageHelper.startPage(0, 0);
		List<LkMatterProject> light = lkMatterProjectService.getLight(new LkMatterProject());
		for (LkMatterProject lkMatterProject:light){
			try {
				lkNoticeService.addNotice(lkMatterProject);
			} catch (Exception e){
				e.printStackTrace();
			}
		}
	}

}
